package com.hdsx.restful.glzt.structure.sd.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.esri.arcgis.geometry.IGeometry;
import com.hdsx.ao.base.BaseOpearte;
import com.hdsx.restful.glzt.roadline.lxxx.bean.Znode;
import com.hdsx.restful.glzt.structure.ql.bean.DoubleValueName;
import com.hdsx.restful.glzt.structure.ql.bean.IntValueName;
import com.hdsx.restful.glzt.structure.ql.bean.StatisticalResult;
import com.hdsx.restful.glzt.structure.sd.bean.Sd;
import com.hdsx.restful.glzt.structure.sd.mapper.SdMapper;
import com.hdsx.restful.glzt.structure.sd.service.SdServer;
import com.hdsx.restful.util.Dao;
/**
 * sdServer实现类
 *
 */
@Service
public class SdServerImpl extends BaseOpearte<Sd>  implements SdServer {

	public SdServerImpl() {
		super("GiS_SD");
	}

	@Resource(name="sdMapper")
	private SdMapper mapper;

	@Override
	public Sd getById(String id) {
		return mapper.queryOne(id);
	}

	@Override
	public boolean addsd(Sd sd) {
		return mapper.add(sd)>0;
	}

	@Override
	public boolean updatesd(Sd sd) {
		return mapper.update(sd)>0;
	}

	@Override
	public boolean deleteById(String id) {
		return mapper.delete(id)>0;
	}

	@Override
	public int querySdCountByLxbm(String lxbm) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("lxbm", lxbm);
		return mapper.countByLxbm(parameter);
	}

	@Override
	public List<Sd> getListByLxbm(String lxbm, int begin, int end) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("lxbm", lxbm);
		parameter.put("begin", begin);
		parameter.put("end", end);
		return mapper.selectListByLxbm(parameter);
	}

	@Override
	public List<Sd> getListByXzqhbm(String xzqhbm, int begin, int end) {
		if(xzqhbm!=null){
			if(xzqhbm.endsWith("0000")){
				xzqhbm=xzqhbm.substring(0,2);
			}else if(xzqhbm.endsWith("00")){
				xzqhbm=xzqhbm.substring(0,4);
			}
		}
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("xzqhbm", xzqhbm);
		parameter.put("begin", begin);
		parameter.put("end", end);
		return mapper.selectListByXzqhbm(parameter);

	}

	@Override
	public int querySdCountByXzqhbm(String xzqhbm) {
		if(xzqhbm!=null){
			if(xzqhbm.endsWith("0000")){
				xzqhbm=xzqhbm.substring(0,2);
			}else if(xzqhbm.endsWith("00")){
				xzqhbm=xzqhbm.substring(0,4);
			}
		}
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("xzqhbm", xzqhbm);
		return mapper.countByXzqhbm(parameter);
	}

	@Override
	public int queryCount(String lxbm,String xzqhbm,String sxxfx,Double qdzh,Double zdzh,String name) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("lxbm", lxbm);
		parameter.put("xzqhbm", xzqhbm);
		parameter.put("sxxfx", sxxfx);
		parameter.put("qdzh", qdzh);
		parameter.put("zdzh", zdzh);
		parameter.put("name", name);
		return mapper.selectCount(parameter);
	}
	@Override
	public List<Sd> queryList(String lxbm,String xzqhbm,String sxxfx,Double qdzh,Double zdzh,String name,int begin, int end) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("lxbm", lxbm);
		parameter.put("xzqhbm", xzqhbm);
		parameter.put("sxxfx", sxxfx);
		parameter.put("qdzh", qdzh);
		parameter.put("zdzh", zdzh);
		parameter.put("name", name);
		parameter.put("begin", begin);
		parameter.put("end", end);
		List<Sd> lists=mapper.selectList(parameter);
		return lists;
	}

	@Override
	public List<Sd> getBySdbm(String sdbm) {
		return mapper.selectBySdbm(sdbm);
	}

	@Override
	public 	List<Sd> countSdflByXzqhbm(String xzqhbm) {
		if(xzqhbm!=null){
			if(xzqhbm.endsWith("0000")){
				xzqhbm=xzqhbm.substring(0,2);
			}else if(xzqhbm.endsWith("00")){
				xzqhbm=xzqhbm.substring(0,4);
			}
		}
		return mapper.countSdflByXzqhbm(xzqhbm);
	}

	@Override
	public List<Sd> countSdflByLxbm(String lxbm) {
		return mapper.countSdflByLxbm(lxbm);
	}

	@Override
	public List<Dao> getShapeById(String id) {
		Sd sd = mapper.getShapeById(id);
		IGeometry shape=selectShape("ID='"+id+"'");
		sd.setShape(shape);
		List<Dao> lists=new ArrayList<Dao>();
		lists.add(new Dao("隧道名称",sd.getSdmc(),sd.getPtx(),sd.getPty()));
		lists.add(new Dao("隧道编码",sd.getSdbm()));
		lists.add(new Dao("所在路线",sd.getLxbm()));
		lists.add(new Dao("中心桩号",sd.getSdzxzh()));
		lists.add(new Dao("隧道分类",sd.getSdfl()));
		return lists;
	}
	
	@Override
	public StatisticalResult countByParameter(Map<String,Object> map) {
		List<IntValueName> seriesData = mapper.countTotalByParameter(map);
		List<DoubleValueName> seriesLengthData = mapper.countLengthByParameter(map);
		List<String> legendData = mapper.selectClassify(map);
		StatisticalResult sr = new StatisticalResult();
		sr.setChartsText("隧道统计");
		sr.setSeriesData(seriesData);
		sr.setSeriesLengthData(seriesLengthData);
		sr.setLegendData(legendData);
		return sr;
	}
	@Override
	public List<Znode> sdNode() {
		List<Znode> sdNode = mapper.sdNode();
		return sdNode;
	}
	/**
	 * 分类细节
	 */
	@Override
	public List<Sd> detail(Map<String, Object> map){
		return mapper.detail(map);
	}
	@Override
	public int countDetail(Map<String, Object> map) {
		return  mapper.countDetail(map);
	}
	
	 @Override
	 public int countTotal(Map<String, Object> map){
		 return mapper.countTotal(map);
	 }
	 
	 @Override
	 public List<Sd> listAll(String lxbm,String xzqhbm,String sxxfx,Double qdzh,
			Double zdzh,String name) {
		return mapper.listAll(lxbm,xzqhbm,sxxfx,qdzh,zdzh,name);
	 }
	 @Override
	public Sd queryById(String id) {
			return mapper.selectById(id);
	}
	 
		@Override
		public List<String> selectName(String name){
			return mapper.selectName(name);
		}
}
